#include <stdio.h>
#include <string.h>
#include <stdlib.h>


/*This program is used to test function system*/
int main(void)
{
	int rv = system("./test.sh");
	if (WIFEXITED(rv))
	{
		printf("subprocess exited, exit code: %d\r\n", WEXITSTATUS(rv));//子进程退出，退出代码
		if (0 == WEXITSTATUS(rv))
		{
			// if command returning 0 means succeed
			printf("command succeed\r\n");
		}
		else
		{
			if (127 == WEXITSTATUS(rv))
			{
				printf("command not found\r\n");
				return WEXITSTATUS(rv);
			}
			else
			{
				printf("command failed: %d\r\n", strerror(WEXITSTATUS(rv)));
				return WEXITSTATUS(rv);
			}
		}
	}
	else
	{
		printf("subprocess exit failed\r\n");//子进程退出失败
		return -1;
	}
}